import android.util.Log;

import com.example.huixingzheng.bean.DataModel;

import retrofit2.Retrofit;
import retrofit2.converter.gson.GsonConverterFactory;

public class DBHelper {
    private static final String BASE_URL = "http://your-server-ip/"; // 替换为你的服务器地址
    private ApiService apiService;

    public DBHelper() {
        Retrofit retrofit = new Retrofit.Builder()
                .baseUrl(BASE_URL)
                .addConverterFactory(GsonConverterFactory.create())
                .build();

        apiService = retrofit.create(ApiService.class);
    }

    public void insertData(DataModel dataModel) {
        apiService.insertData(dataModel).enqueue(new Callback<Void>() {
            @Override
            public void onResponse(Call<Void> call, Response<Void> response) {
                if (response.isSuccessful()) {
                    Log.d("DBHelper", "Data inserted successfully.");
                } else {
                    Log.e("DBHelper", "Error inserting data: " + response.message());
                }
            }

            @Override
            public void onFailure(Call<Void> call, Throwable t) {
                Log.e("DBHelper", "Error inserting data: " + t.getMessage());
            }
        });
    }
}